package com.definesys.smecrailtransit.module.lineCharts.viewModel;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.View;

import com.bigkoo.pickerview.OptionsPickerView;
import com.definesys.smecrailtransit.module.lineCharts.beans.MonReport;
import com.hwangjr.rxbus.Bus;

import java.util.ArrayList;
import java.util.WeakHashMap;

/**
 * Created by xupeizuo on 2018/3/8.
 */

public class MonthReportViewModel {

    private Bus mRxBus;
    private Context context;
    private OptionsPickerView siteOptions;
    private MonReport monReport=new MonReport();
    private ArrayList<String> years=new ArrayList<>();
    private ArrayList<ArrayList<String>> mons=new ArrayList<>();
    public static final String selectedMonth="selectedMonth";
    private WeakHashMap<String,String> map=new WeakHashMap<>();


    public MonthReportViewModel(Bus mRxBus, Context context) {
        this.mRxBus = mRxBus;
        this.context = context;
        initData();
    }

    private void initData(){
        years.add("2018");
//        years.add("2017");
        ArrayList<String> arrayList=new ArrayList<>();
        arrayList.add("01");
        arrayList.add("02");
        arrayList.add("03");
        arrayList.add("04");
        arrayList.add("05");
        arrayList.add("06");
        arrayList.add("07");
        arrayList.add("08");
        arrayList.add("09");
        arrayList.add("10");
        arrayList.add("11");
        arrayList.add("12");
        mons.add(arrayList);
        mons.add(arrayList);
    }

    public void showMonthData(){
        if(siteOptions == null){
            initOptions();
        }
        siteOptions.show();
    }

    public void initOptions(){
        siteOptions=new OptionsPickerView.Builder(context, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                String seYears=years.get(options1);
                String seMonth=mons.get(options1).get(options2);
                map.put("selected",seYears+"-"+seMonth);
                map.put("selectedZW",seYears+"年"+seMonth+"月");
                mRxBus.post(selectedMonth,map);
            }
        }).setTitleText("月份选择")
                .setContentTextSize(25)//设置滚轮文字大小
                .setDividerColor(Color.LTGRAY)//设置分割线的颜色
                .setBgColor(Color.WHITE)
                .setTitleBgColor(Color.parseColor("#A0D7C8"))
                .setTitleColor(Color.WHITE)
                .setCancelColor(Color.WHITE)
                .setSubmitColor(Color.WHITE)
                .setTextColorCenter(Color.parseColor("#A0D7C8"))
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setBackgroundId(0x66000000) //设置外部遮罩颜色
                .build();

        siteOptions.setPicker(years, mons);
    }

    public MonReport getMonReport() {
        return monReport;
    }

    public void setMonReport(MonReport monReport) {
        this.monReport = monReport;
    }
}
